home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 424 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  45 lines

  1. Newsgroups: comp.lang.c++
  2. Path: artemis.sto.fdata.se!news
  3. From: Niklas Mellin <niklas.mellin@sto.fdata.se>
  4. Subject: Re: Question about destructor...
  5. Sender: news@artemis.sto.fdata.se (UseNet NetNews)
  6. Message-ID: <30EBD3C5.429C@sto.fdata.se>
  7. Date: Thu, 4 Jan 1996 13:19:01 GMT
  8. Content-Transfer-Encoding: 7bit
  9. Content-Type: text/plain; charset=us-ascii
  10. References: <4cegke$p5@newsbf02.news.aol.com> <4ces35$3iq$1@mhafn.production.compuserve.com>
  11. Mime-Version: 1.0
  12. X-Mailer: Mozilla 2.0b4 (WinNT; I)
  13. Organization: WM-data F÷rsvarsdata AB, Sweden
  14.  
  15. Nil Bannerjee wrote:
  16. >    If you call the destructor of A from B's destructor then this
  17. > will take care of the inherited attributes.
  18. > CB::~CB()
  19. > {
  20. >     //your stuff..
  21. >     ..
  22. >     ..
  23. >     ~CA();
  24. > }
  25.  
  26. WRONG! WRONG! WRONG!
  27.  
  28. You are lucky that your compiler wont let this through!
  29. When an object is destroyed all base class destructors will
  30. be called automatically. You don't have to do anything, and
  31. you can't prevent it.
  32.  
  33. If you call the base class' destructor explicitly it will be
  34. called twice, and the 2nd time will very likely lead to program
  35. crashes.
  36.  
  37. The reason the above code does not pass the compliler (at least
  38. not borland 4.5) is that the form to call the destructor would
  39. be: (CA*)this->~CA(); But please: don't do this.
  40.  
  41. ---
  42. Niklas Mellin
  43.